package edu.sctu.zcy.month201505.subwaysystem.V2;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by user24 on 2015/6/2.
 */
public class EnterAndExitTheSubweyStation {


    public void enterAndExit() {

        CheckTheXingLiOfPassenger checkTheXingLiOfPassenger = new CheckTheXingLiOfPassenger();
        List<Passenger> passengerList = new SetPassenger().setPassengerInfo();

       for (Passenger passenger :passengerList){

           DeductionsRules deductionsRules = new DeductionsRules();
            System.out.println("姓名：" + passenger.getName() + "\n编号："
                    + passenger.getNumber());

            System.out.println("起点站："+passenger.getStartStation()+
                    "  终点站："+passenger.getEndStation());


            if (passenger.isIs_Card()) {
                if (checkTheXingLiOfPassenger.isPackage(passenger)) {

                    System.out.println("行李可能含有危险物品");
                }
                if (checkTheXingLiOfPassenger.isWater(passenger)) {

                    System.out.println("水可能含有危险物品");
                } else {

                    Date date = new Date();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    System.out.println("进站,及其时间为："+ simpleDateFormat.format(date));
                }

                if (new DeductionsRules().getPrice(passenger) <= passenger.getCardBalance()) {

                    System.out.println("余额充足，无需充值");
                    System.out.println("扣费"+deductionsRules.getPrice(passenger)+"元");

                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.MINUTE,
                            (deductionsRules.getCountStation
                                    (passenger.getStartStation(),passenger.getEndStation()))*2);

                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    System.out.println("出站,及其时间："+simpleDateFormat.format(calendar.getTime()));

                    System.out.println();

                } else {

                    deductionsRules.setRecharge(10, passenger);
                    System.out.println("充值成功，扣费后余额为" + (passenger.getCardBalance()
                            - deductionsRules.getPrice(passenger)));

                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.MINUTE,
                            +(deductionsRules.getCountStation
                                    (passenger.getStartStation(),passenger.getEndStation()))*2);

                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


                    System.out.println("出站,及其时间："+simpleDateFormat.format(calendar.getTime()));
                }

            } else {

                System.out.println("你需要办卡才能入站坐车");
                System.out.println("你需付费" + deductionsRules.getPrice(passenger) + "元");

                if (checkTheXingLiOfPassenger.isPackage(passenger)) {

                        System.out.println("行李可能含有危险物品");
                    }
                    if (checkTheXingLiOfPassenger.isWater(passenger)) {

                        System.out.println("水可能含有危险物品");
                    } else {

                        Date date = new Date();
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        System.out.println("进站,及其时间为："+ simpleDateFormat.format(date));
                    }
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.MINUTE,
                            +(deductionsRules.getCountStation
                                    (passenger.getStartStation(),passenger.getEndStation()))*2);

                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    System.out.println("出站,及其时间："+simpleDateFormat.format(calendar.getTime()));
                    System.out.println();
                }
            }
        }
    }

